﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Agnes.TaskManager
{
    /// <summary>
    /// Weekdays.xaml 的交互逻辑
    /// </summary>
    public partial class WeekdaysCtrl : UserControl
    {
        /// <summary>
        /// Weekdays Dependency Property
        /// </summary>
        public static DependencyProperty WeekdaysProperty
            = DependencyProperty.Register("Weekdays", typeof(Weekdays), typeof(WeekdaysCtrl), new PropertyMetadata(new PropertyChangedCallback(OnWeekdaysChanged)));

        /// <summary>
        /// Weekdays Binding
        /// </summary>
        public Weekdays Weekdays
        {
            get { return (Weekdays)base.GetValue(WeekdaysProperty); }
            set { base.SetValue(WeekdaysProperty, value); }
        }

        private static void OnWeekdaysChanged(DependencyObject obj,DependencyPropertyChangedEventArgs e)
        {
            WeekdaysCtrl wc = obj as WeekdaysCtrl;
            wc.InitCtrl();
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public WeekdaysCtrl()
        {
            InitializeComponent();
        }

        private void InitCtrl()
        {
            Monday.IsChecked = (Weekdays & Weekdays.Monday) == 0 ? false : true;
            Tuesday.IsChecked = (Weekdays & Weekdays.Tuesday) == 0 ? false : true;
            Wednesday.IsChecked = (Weekdays & Weekdays.Wednesday) == 0 ? false : true;
            Thursday.IsChecked = (Weekdays & Weekdays.Thursday) == 0 ? false : true;
            Friday.IsChecked = (Weekdays & Weekdays.Friday) == 0 ? false : true;
            Saturday.IsChecked = (Weekdays & Weekdays.Saturday) == 0 ? false : true;
            Sunday.IsChecked = (Weekdays & Weekdays.Sunday) == 0 ? false : true;

        }

        private void Sunday_Checked(object sender, RoutedEventArgs e)
        {
            Weekdays |= Weekdays.Sunday;
        }

        private void Sunday_Unchecked(object sender, RoutedEventArgs e)
        {
            Weekdays &= (~Weekdays.Sunday);
        }

        private void Monday_Checked(object sender, RoutedEventArgs e)
        {
            Weekdays |= Weekdays.Monday;   
        }

        private void Monday_Unchecked(object sender, RoutedEventArgs e)
        {
            Weekdays &= (~Weekdays.Monday);
        }

        private void Tuesday_Checked(object sender, RoutedEventArgs e)
        {
            Weekdays |= Weekdays.Tuesday;
        }

        private void Tuesday_Unchecked(object sender, RoutedEventArgs e)
        {
            Weekdays &= (~Weekdays.Tuesday);
        }

        private void Wednesday_Checked(object sender, RoutedEventArgs e)
        {
            Weekdays |= Weekdays.Wednesday;
        }

        private void Wednesday_Unchecked(object sender, RoutedEventArgs e)
        {
            Weekdays &= (~Weekdays.Wednesday);
        }

        private void Thursday_Checked(object sender, RoutedEventArgs e)
        {
            Weekdays |= Weekdays.Thursday;
        }

        private void Thursday_Unchecked(object sender, RoutedEventArgs e)
        {
            Weekdays &= (~Weekdays.Thursday);
        }

        private void Friday_Checked(object sender, RoutedEventArgs e)
        {
            Weekdays |= Weekdays.Friday;
        }

        private void Friday_Unchecked(object sender, RoutedEventArgs e)
        {
            Weekdays &= (~Weekdays.Friday);
        }

        private void Saturday_Checked(object sender, RoutedEventArgs e)
        {
            Weekdays |= Weekdays.Saturday;
        }

        private void Saturday_Unchecked(object sender, RoutedEventArgs e)
        {
            Weekdays &= (~Weekdays.Saturday);
        }
    }
}
